﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.EventHandler;
using MapComponentSprite;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using UIComponentSprite.Building;
using UIComponentSprite.Building.Menu;
using UIComponentSprite.Date;
using UIComponentSprite.Grid;
using UIComponentSprite.Screen;
using UIComponentSprite.SmallMap;

namespace UIComponentSprite
{
   public class SpriteController
   {
       private MapBackgroundLayerSprite _mapBackgroundLayerSprite = MapBackgroundLayerSprite.GetInstance();
       private BuildingBaseInfoSprite _buildingBaseInfoSprite = new BuildingBaseInfoSprite();
       private MapCloseButtonSprite _mapCloseButtonSprite = new MapCloseButtonSprite();
       private MapOpenButtonSprite _mapOpenButtonSprite = new MapOpenButtonSprite();
       private SmallMapSprite _smallMapSprite;
       private MenuController _menuController = new MenuController();
       private PauseBtnSprite _pauseBtnSprite = new PauseBtnSprite();
       private StartBtnSprite _startBtnSprite;
       private DateBackGroundSprite _dateBackGroundSprite = new DateBackGroundSprite();
     
       private GridButtonSprite _gridButtonSprite=new GridButtonSprite();
       public SpriteController()
       {
           _mapBackgroundLayerSprite.ClickLeftEvent += new ClickLeftEventHandler(_menuController.UnShowByAre);//关闭建筑主菜单
           _mapBackgroundLayerSprite.ClickRightEvent += new ClickRightEventHandler(_menuController.UnShowByAre);//关闭建筑主菜单

           //注册城池建筑物的鼠标点击事件
           foreach (var build in BuildingUnitSprite.BuildingUnitSprites)
           {
               build.ClickLeftEvent += new ClickLeftEventHandler(_menuController.MenuSprite1.ClickLeftEventHandler);
               build.MoveOnEvent += new MoveOnEventHandler(_buildingBaseInfoSprite.MouseMoveOnEventHandler);
               build.MoveOutEvent += new MoveOutEventHandler(_buildingBaseInfoSprite.MouseMoveOutEventHandler);
           }
            _startBtnSprite= new StartBtnSprite(@"Images\views\screen\Play", _pauseBtnSprite);
           _smallMapSprite = new SmallMapSprite(_mapCloseButtonSprite, _mapOpenButtonSprite);
           _mapCloseButtonSprite.ClickLeftEvent += new ClickLeftEventHandler(_mapOpenButtonSprite.ChangeShowing);
           _mapOpenButtonSprite.ClickLeftEvent += new ClickLeftEventHandler(_mapCloseButtonSprite.ChangeShowing);
           _mapCloseButtonSprite.ChangeShowing(null);
           _menuController.SetShowing(true);
           _startBtnSprite.SetShowing(true);
           //日期显示
           _dateBackGroundSprite.SetShowing(true);
           _gridButtonSprite.SetShowing(true);
       }
       /// <summary>
       /// Allows the game component to update itself.
       /// </summary>
       /// <param name="gameTime">Provides a snapshot of timing values.</param>
       public void Update(GameTime gameTime)
       {
        
          _mapCloseButtonSprite.Update(gameTime);
           _buildingBaseInfoSprite.Update(gameTime);
           _mapOpenButtonSprite.Update(gameTime);
           _smallMapSprite.Update(gameTime);
           _menuController.Update(gameTime);
           _startBtnSprite.Update(gameTime);
           _pauseBtnSprite.Update(gameTime);
           _dateBackGroundSprite.Update(gameTime);
           _gridButtonSprite.Update(gameTime);
       }
       public void Draw(GameTime gameTime)
       {
         
           _mapCloseButtonSprite.Draw(gameTime);
           _buildingBaseInfoSprite.Draw(gameTime);
           _mapOpenButtonSprite.Draw(gameTime);
           _smallMapSprite.Draw(gameTime);
           _menuController.Draw(gameTime);
           _startBtnSprite.Draw(gameTime);
           _pauseBtnSprite.Draw(gameTime);
           _dateBackGroundSprite.Draw(gameTime);
           _gridButtonSprite.Draw(gameTime);
       }
    }
}
